package com.gulimall.coupon.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.gulimall.coupon.service.impl.SeckillSessionServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.gulimall.coupon.entity.SeckillSessionEntity;
import com.gulimall.coupon.service.SeckillSessionService;
import com.common.utils.PageUtils;
import com.common.utils.R;

import javax.annotation.Resource;


/**
 * 秒杀活动场次
 *
 * @author Rookie-886
 * @email ${email}
 * @date 2021-03-14 22:21:00
 */
@RestController
@RequestMapping("coupon/seckillsession")
public class SeckillSessionController {
    @Resource
    private SeckillSessionServiceImpl seckillSessionServiceImpl;

    @GetMapping("/getLasted3DaysList")
    public R getLasted3DaysList(){
        List<SeckillSessionEntity> seckillSessionEntityList =  seckillSessionServiceImpl.getLasted3DaysList();
        return R.ok().put("data",seckillSessionEntityList);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("coupon:seckillsession:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = seckillSessionServiceImpl.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("coupon:seckillsession:info")
    public R info(@PathVariable("id") Long id){
		SeckillSessionEntity seckillSession = seckillSessionServiceImpl.getById(id);

        return R.ok().put("seckillSession", seckillSession);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("coupon:seckillsession:save")
    public R save(@RequestBody SeckillSessionEntity seckillSession){
        seckillSessionServiceImpl.save(seckillSession);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("coupon:seckillsession:update")
    public R update(@RequestBody SeckillSessionEntity seckillSession){
        seckillSessionServiceImpl.updateById(seckillSession);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("coupon:seckillsession:delete")
    public R delete(@RequestBody Long[] ids){
        seckillSessionServiceImpl.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
